<template>
  <el-dialog v-dialogDrag :visible.sync="dialog" width="580px" :close-on-click-modal="false" :before-close="reset">
    <span slot="title" class="dialog-title">{{disabled?'开票详情':'开票'}}</span>
    <div class="dialoginfo">
      <el-form ref="reffromDate" :rules="rules" :model="low" label-width="140px" :disabled="disabled">
        <el-form-item label="财务编码：">
          <span>{{low.financialCode}}</span>
        </el-form-item>
        <el-form-item label="工程名称：">
          <span>{{low.engineeringName}}</span>
        </el-form-item>
        <el-form-item label="合同单位：">
          <span>{{low.contractUnit}}</span>
        </el-form-item>
        <el-form-item label="发票类别：">
          <span>{{low.invoiceCategory}}</span>
        </el-form-item>
        <el-form-item label="申请开票金额：">
          {{low.applicantAmount}}元
        </el-form-item>
        <el-form-item prop="invoiceNo" label="开票号：">
          <el-input v-model="low.invoiceNo" placeholder="请输入" clearable>
          </el-input>
        </el-form-item>
        <el-form-item prop="invoiceAmount" label="开票金额：">
          <el-input v-model="low.invoiceAmount" placeholder="请输入" type="Number" clearable @change="low.invoiceAmount>low.applicantAmount?low.invoiceAmount=low.applicantAmount:''">
            <template slot="append">元</template>
          </el-input>
        </el-form-item>
        <!-- <el-form-item prop="email" label="接收邮箱：">
          <el-input v-model="low.email" placeholder="请输入" clearable></el-input>
        </el-form-item> -->
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button class="bottom_all_two" @click="reset">取 消</el-button>
      <el-button class="bottom_all" @click="submit">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
import {
  saveOrUpdate
} from "@/api/internetSales/engineeringNotes.js";
export default {
  props: {
    dialog: {
      type: Boolean,
      default: false
    },
    disabled: {
      type: Boolean,
      default: false
    },
    low: {
      type: Object,
      default: new Object()
    }
  },
  data() {
    return {
      rules: {
        invoiceNo: [{ required: true, message: "请输入开票号", trigger: "blur" }],
        invoiceAmount: [{ required: true, message: "请输入开票金额", trigger: "blur" }],
        email: [{ required: true, message: "请输入接收邮箱", trigger: "blur" }],
      },
    }
  },
  watch: {
    dialog() {
      if (this.dialog) {
        setTimeout(() => {
          this.$refs.reffromDate.clearValidate();
        }, 10)
      }
    },
  },
  methods: {
    reset() {
      this.$emit('reset', 'dialog1')
    },
    submit() {
      this.low.dataStatus = 1
      this.$refs.reffromDate.validate((valid) => {
        if (valid) {
          saveOrUpdate(this.low).then(res => {
            if (res.code == 1001) {
              this.$message({
                message: '保存成功',
                type: "success",
              });
            }
            this.$emit('submit', 'dialog1')
          })
        } else {
          return false;
        }
      });

    },
  }
}
</script>
<style lang="scss" scoped>
.el-input,
.el-select {
  width: 240px;
}
</style>


